package com.platform.mesh.web.filter;

import cn.hutool.core.util.CharsetUtil;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

/**
 * @description 配置字符编码
 * @author 蝉鸣
 */
@Component
public class EncodingFilter extends OncePerRequestFilter {

    /**
     * 功能描述:
     * 〈配置字符编码〉
     * @param request request
     * @param response response
     * @param filterChain filterChain
     * @author 蝉鸣
     */
    @Override
    protected void doFilterInternal(HttpServletRequest request, @NotNull HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
            request.setCharacterEncoding(CharsetUtil.UTF_8);
            filterChain.doFilter(request,response);
    }
}
